<%@page import="org.proddevplm.dao.data.stakeholders.Stakeholder"%>
<%@page import="java.util.List"%>
<%@page import="org.proddevplm.constants.ControllerConstants"%>
<%@page import="org.proddevplm.business.tools.constants.ToolsConstants" %>
<%@page import="org.proddevplm.business.activity.constants.ActivityConstants" %>
<script>

	$(function(){
		$( "button" ).button();
	});

	$(document).ready(function(){ 
		$("#viewShDB").tablesorter({
			widgets:['zebra'],
			headers:{
			4: {sorter: false}
			}
	      }); 
	    });

</script>

<script type="text/javascript">

	function removeSH(shName, tRow){
		var confirmSHDeletion = confirm("Do you want to remove this stakeholder?");
		if(confirmSHDeletion){
			var arguments = "shName="+shName;
			var tableRow = tRow;
			$("#"+tableRow).hide();
			ajaxCall("toolsManager", "6", arguments, null);
			alert('Stakeholder deleted successfully');
		}
	}
	
	function finishActivity(name){
		$("#activityName").val(name);
		document.forms['finishActivityForm'].submit();
	}
	
	function doneSH(){
		document.forms["shFormFwd"].submit();
	}

</script>

<%
	List<Stakeholder> shResults = (List)session.getAttribute("shResults");
	Stakeholder stakeholder;
	String[] lcStages = {"Concept", "Development", "Production", "Use", "Support", "Retirement"};
	String activityName = "";
%>

<div align="center">
	<div style="width:auto">
		<table id="viewShDB" class="tablesorter" style="width:100%" rules="rows" frame="hsides" bordercolor="#DBDBDB">
			<thead>
				<tr>
					<th style="width:20%">Stakeholder's name</th>
					<th style="width:35%">Stakeholder's details</th>
					<th style="width:20%">Life cycle stage</th>
					<th style="width:20%">Added by</th>
					<th style="width:5%">Action</th>	
				</tr>		
			</thead>
			<tbody>
				<%
				for(int i=0; i<shResults.size(); i++){
					stakeholder = shResults.get(i);
					activityName = stakeholder.getActivityName();%>
					<tr id="row<%=i+1%>">
						<td><%=stakeholder.getShName()%></td>
						<td><%=stakeholder.getDetails()%></td>
						<td><%
						String stages = stakeholder.getLcStage();
						int[] indexes = new int[6];
						for (int j=0; j<stages.length(); j++)
							indexes[j] = Integer.valueOf(stages.substring(j,j+1));
						for (int k=0; k<stages.length(); k++){
							int aux = indexes[k]-1;%>
							<%= lcStages[aux]+"</br>"%>
						<%}
						%></td>
						<td><%=stakeholder.getAuthor() %></td>
						<td style="text-align:center"><img src="/proddev/images/delete1.png" onclick="removeSH('<%=stakeholder.getShName()%>', 'row<%=i+1%>')" align="middle" width="20" height="20"/></td>
					</tr>
				<%}
				%>
			
			</tbody>
		</table>
		
		<button id="finishActivity" name="finishActivity" onclick="finishActivity('<%=activityName %>')" style="width:250px; margin:20px; font-weight:bold;">Finish activity</button>
		
		<form name="finishActivityForm" method="post" action="/proddev/controller">
			<input type = "hidden" name = "<%=ControllerConstants.MANAGER_KEY%>" value = "<%=ControllerConstants.ACTIVITY_MANAGER%>"/>
			<input type = "hidden" name = "<%=ControllerConstants.METHOD_KEY%>" value = "<%=ActivityConstants.CHANGE_STATUS%>"/>
			<input type="hidden" name="activityName" id="activityName">	
		</form>
		<div style="clear:both"></div>			
	</div> 
</div>